package cn.monkey.service.impl;

import cn.monkey.mapper.MenuMapper;
import cn.monkey.pojo.Menu;
import cn.monkey.service.MenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper,Menu> implements MenuService {
    @Autowired
    MenuMapper menuMapper;
    public List<Menu> getMenuAll(){
        List<Menu> menuAll = menuMapper.selectList(null);
        List<Menu> menuFirst = new ArrayList<>();
        for (Menu menu : menuAll) {
            if(menu.getParentid()==null){
                carding(menu,menuAll);
                menuFirst.add(menu);
            }
        }
        return menuFirst;
    }
    public void carding(Menu menu,List<Menu> menuAll){
        menu.setMenuList(new ArrayList<>());
        for (Menu menu1 : menuAll) {
            if(menu.getMid()==menu1.getParentid()){
                menu.getMenuList().add(menu1);
                carding(menu1,menuAll);
            }
        }
    }

}
